<template>
  <div class="policy">
    <div class="policy-option">
      <em>发布机构：</em>
      <span
        :class="[activeLever == '全部' ? 'active' : '']"
        @click="changeLevel('全部')"
        >全部</span
      >
      <span
        :class="[activeLever == '国家' ? 'active' : '']"
        @click="changeLevel('国家')"
        >国家</span
      >
      <span
        :class="[activeLever == '省级' ? 'active' : '']"
        @click="changeLevel('省级')"
        >省级</span
      >
      <span
        :class="[activeLever == '市级' ? 'active' : '']"
        @click="changeLevel('市级')"
        >市级</span
      >
      <span
        :class="[activeLever == '区县' ? 'active' : '']"
        @click="changeLevel('区县')"
        >区县</span
      >
      <span
        :class="[activeLever == '开发区' ? 'active' : '']"
        @click="changeLevel('开发区')"
        >开发区</span
      >
      <ul
        :class="[
          activeLever == '区县' ? 'xq' : '',
          activeLever == '开发区' ? 'kfq' : '',
        ]"
      >
        <li
          v-for="item of institution[activeLever]"
          :key="item.label"
          :class="[activeSecond == item.label ? 'active' : '']"
          @click="changeSecond(item.label)"
        >
          {{ item.label }}
        </li>
      </ul>
    </div>
    <div class="time-options ">
      <div>
        <em>年份筛选：</em>

        <el-date-picker
          v-model="year"
          type="year"
          placeholder="请选择年份"
          value-format="yyyy"
          @change="search"
        >
        </el-date-picker>
      </div>
      <div class="search-name">
        <em>政策名称：</em>
        <el-input
          v-model="keyword"
          placeholder="请输入政策名称"
          type="text"
          clearable
          @keydown.enter.native="search"
        />
        <span @click="search">搜索</span>
      </div>
    </div>
    <div class="list" v-if="total != 0">
      <div
        class="list_item"
        v-for="item of list"
        :key="item.id"
        @click="goPolicy(item.id)"
      >
        <p class="item_title">{{ item.name }}</p>
        <p class="division"></p>
        <p class="flex_p">
          <span
            >发布机构：<span>{{ item.org }}</span>
          </span>
          <span
            >发布时间：<span>{{ item.pubdate }}</span>
          </span>
        </p>
        <strong>
          查看详情
        </strong>
      </div>
    </div>
    <el-pagination
      v-if="total != 0"
      @current-change="handleCurrentChange"
      :current-page.sync="page"
      :page-size="per_page"
      layout=" prev, pager, next"
      :total="total"
    >
    </el-pagination>
    <div class="empty" v-if="total == 0">
      <img src="~@img/public/img-empty.png" alt="" />
      <p>未查找到匹配的政策~</p>
    </div>
  </div>
</template>
<script>
import { policy } from "@api/atlas";
export default {
  data() {
    return {
      activeLever: "全部",
      activeSecond: "全部",
      keyword: "",
      year: "",
      institution: {
        全部: [
          {
            label: "全部",
          },
        ],
        国家: [
          {
            label: "全部",
          },
          { label: "国务院" },
          { label: "发改委" },
          { label: "科技部" },
          { label: "工信部" },
          { label: "国家能源局" },
          { label: "国家药监局" },
        ],
        省级: [
          {
            label: "全部",
          },
          {
            label: "山西省政府",
          },
          {
            label: "省政府办公厅",
          },
          {
            label: "省发改委",
          },
          {
            label: "省科技厅",
          },
          {
            label: "省工信厅",
          },
        ],
        市级: [
          {
            label: "全部",
          },
        ],
        区县: [
          {
            label: "全部",
          },
          {
            label: "小店区",
          },
          {
            label: "迎泽区",
          },
          {
            label: "杏花岭区",
          },
          {
            label: "尖草坪区",
          },
          {
            label: "万柏林区",
          },
          {
            label: "晋源区",
          },
          {
            label: "古交市",
          },
          {
            label: "清徐县",
          },
          {
            label: "阳曲县",
          },
          {
            label: "娄烦县",
          },
        ],
        开发区: [
          {
            label: "全部",
          },
          {
            label: "综改示范区",
          },
          {
            label: "中北高新区",
          },
          {
            label: "清徐开发区",
          },
          {
            label: "阳曲示范区",
          },
          {
            label: "西山示范区",
          },
        ],
      },
      list: [],
      page: 1,
      per_page: 4,
      total: 0,
    };
  },
  props: ["industry_id", "industry_cate"],
  watch: {
    industry_id(nv, ov) {
      if (nv == ov) return;
      this.page = 1;
      this.activeSecond == "全部";
      this.activeLever == "全部";
      this.year = "";
      this.keyword = "";
      this.getPolicyList();
    },
  },
  mounted() {
    this.getPolicyList();
  },
  methods: {
    async getPolicyList() {
      let res = await policy({
        inid: this.industry_id || "4",
        page: this.page,
        perpage: this.per_page,
        // category: "",
        org: this.activeSecond == "全部" ? "" : this.activeSecond,
        year: this.year || "",
        keyword: this.keyword,
        level: this.activeLever == "全部" ? "" : this.activeLever,
      });
      if (res.code && res.code != 0) {
        this.list = [];
        this.total = 0;
      } else {
        this.list = res.data;
        this.total = res.size;
      }
    },
    changeLevel(level) {
      this.page = 1;
      this.activeLever = level;
      this.activeSecond = "全部";
      this.getPolicyList();
    },
    changeSecond(level) {
      this.page = 1;
      this.activeSecond = level;
      this.getPolicyList();
    },
    search() {
      this.page = 1;
      this.getPolicyList();
    },
    goPolicy(id) {
      this.$router.push({
        name: "policy",
        params: { activeMenu: "atlas", id },
      });
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getPolicyList();
    },
  },
};
</script>
<style lang="less" scoped>
em {
  font-size: 14px;
  font-weight: 400;
  color: #333333 !important;
  font-family: Microsoft YaHei;
}
.policy-option {
  cursor: default;
  span {
    display: inline-block;
    width: 80px;
    text-align: center;
    height: 32px;
    line-height: 32px;
    background: #f0f0f0;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 400;
    color: #666666;
    margin-right: 10px;
    &.active {
      background: #446db3;
      font-weight: bold;
      color: #ffffff;
    }
  }
  ul {
    display: flex;
    justify-content: flex-start;
    margin: 20px 0 20px 80px;
    li {
      position: relative;
      padding: 0 13px;
      height: 12px;
      line-height: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #666666;
      &::before {
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        width: 1px;
        height: 12px;
        background: #cccccc;
      }
      &:first-of-type {
        padding-left: 0;
        &::before {
          background: transparent;
        }
      }
    }
    li.active {
      font-weight: bold;
      color: #5889dc;
    }
  }
}
.time-options {
  display: flex;
  justify-content: flex-start;
  margin: 20px 0 24px;
  div {
    margin-right: 20px;
  }
  .search-name {
    flex: 0 0 600px;
    position: relative;
    /deep/ .el-input {
      width: 300px;
      height: 32px;
      line-height: 32px;
      background: #ffffff;
      border-radius: 5px;
      .el-input__inner {
        padding-right: 100px;
        width: 300px;
        height: 32px;
        line-height: 32px;
        background: #ffffff;
        border-radius: 5px;
      }
      .el-input__suffix {
        position: absolute;
        right: 70px;
        top: 0;
      }
    }
    span {
      position: absolute;
      margin-left: -90px;
      margin-top: 1px;
      display: inline-block;
      width: 70px;
      height: 32px;
      line-height: 32px;
      text-align: center;
      background: #5889dc;
      border-radius: 0px 5px 5px 0px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #ffffff;
      cursor: default;
    }
  }
}
/deep/ .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 140px;
  height: 32px;
  background: #ffffff;
  border-radius: 5px;
}
/deep/ .el-date-editor.el-input .el-input__inner {
  width: 140px;
  height: 32px;
  line-height: 32px;
  background: #ffffff;
  border-radius: 5px;
}
/deep/ .el-input__icon {
  line-height: 32px;
}

.list {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.list_item {
  position: relative;
  box-sizing: border-box;
  margin-bottom: 10px;
  padding: 0 14px 0 46px;
  width: 100%;
  height: 108px;
  background: #ffffff;
  box-shadow: 0px 0px 6px 0px rgba(86, 86, 86, 0.2);
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  .item_title {
    height: 66px;
    line-height: 66px;
    font-size: 22px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #333333;
    text-align: left;
  }

  .division {
    width: 98%;
    height: 2px;
    border-radius: 2px;
    background: #eeeeee;
  }
  .flex_p {
    height: 42px;
    line-height: 42px;
    width: 98%;
    display: flex;
    justify-content: flex-start;
    span {
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #999999;
      span {
        color: #333;
        margin-right: 150px;
      }
    }
  }
  strong {
    position: absolute;
    right: 30px;
    top: 40px;
    margin-top: -14px;
    font-size: 18px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #aaaaaa;
    padding-right: 20px;
    &::after {
      position: absolute;
      right: 0;
      top: 0;
      display: block;
      width: 18px;
      height: 28px;
      content: "";
      background: url("~@img/public/icon-information-normal.png") no-repeat
        center;
    }
  }
  &:hover {
    .item_title {
      font-size: 22px;
      font-weight: bold;
      color: #446db3;
    }

    &::after {
      position: absolute;
      top: 0;
      left: -1px;
      display: inline-block;
      content: "";
      width: 7px;
      height: 100%;
      background: #446db3;
      border-radius: 6px 0px 0px 6px;
    }
    strong {
      color: #446db3;
      &::after {
        background: url("~@img/public/icon-information-hover.png") no-repeat
          center;
      }
    }
  }
}
.empty {
  text-align: center;
  img {
    margin-top: 50px;
    width: 302px;
    height: 216px;
  }
  p {
    margin-top: 20px;
    color: #446db3;
  }
}
/*
  *常用电脑尺寸  1680 * 900
  *              1536 * 864
  *              1440 * 900
  *ipad pro      1366 * 1024
  *ipad mini     1024 * 768
  *ipad          1024 * 768
 */
/*分辨率低于1680，采用下面的样式*/
@media screen and (max-device-width: 1680px) {
  .policy-option ul li {
    padding: 0 8px;
  }
}
/*分辨率低于1536，采用下面的样式*/
@media screen and (max-device-width: 1536px) {
  .policy-option ul li {
    padding: 0 6px;
  }
  .list_item {
    height: 92px;
  }
  .list_item .item_title {
    height: 50px;
    line-height: 50px;
    font-size: 16px;
  }
  .list_item:hover .item_title {
    font-size: 16px;
  }
  .list_item strong {
    top: 24px;
  }
  .time-options {
    margin: 0px 0 10px;
  }
  .policy-option ul {
    margin: 10px 0 10px 80px;
  }
}
/*分辨率低于1440，采用下面的样式*/
@media screen and (max-device-width: 1440px) {
  .policy-option ul li {
    padding: 0 4px;
  }
}
/*分辨率低于1366，采用下面的样式*/
@media screen and (max-device-width: 1366px) {
  .policy-option ul {
    flex-wrap: wrap;
    &.xq li {
      padding: 0 8px;
      width: 100px;
      margin-bottom: 10px;
      text-align: center;
    }
    &.kfq li {
      padding: 0 8px;
      width: 180px;
      margin-bottom: 10px;
      text-align: center;
    }
  }
  .list_item:hover .item_title {
    font-size: 13px;
  }
}
/*分辨率低于1180，采用下面的样式*/
@media screen and (max-device-width: 1180px) {
  .time-options .search-name {
    flex: 0 0 460px;
  }
  .list_item {
    height: 80px;
  }
  .list_item:hover .item_title {
    font-size: 12px;
  }
  .policy-option span {
    font-size: 14px;
  }
  .list_item .item_title {
    height: 40px;
    line-height: 40px;
    font-size: 12px;
  }
  .list_item .flex_p span {
    font-size: 12px;
  }
}
/*分辨率低于1024，采用下面的样式*/
@media screen and (max-device-width: 1024px) {
  .time-options .search-name {
    flex: 0 0 380px;
  }
  /deep/ .time-options .search-name .el-input .el-input__inner {
    width: 270px;
  }
  /deep/ .time-options .search-name .el-input {
    width: 270px;
  }
  .list_item .flex_p span span {
    margin-right: 100px;
  }
  .list_item .item_title {
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 440px;
    overflow: hidden;
  }
  .policy {
    height: 538px;
    overflow-y: auto;
  }
}
</style>
